{extends file='admin/layout/dialog.tpl'}
{block title}企业管理{/block}
{block breadcrumb}
    <li>企业管理 <i class="icon-angle-right"></i></li>
    <li> 企业列表</li>
{/block}
{block main}

    <div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                首页企业广告列表
            </header>
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>企业名称</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                {foreach $data as $item}
                    <tr>
                        <td><input type="radio" name=""> {$item.id}</label></td>
                        <td>{$item.name|default:'--'|escape}</td>
                        <td></td>
                    </tr>
                {/foreach}
                </tbody>
            </table>
            {include 'admin/layout/paginate.tpl'}
        </section>
    </div>
</div>
{/block}
{block script}
    <script charset="utf-8" src="{asset('admin/layer/layer.js')}"></script>
    <script>
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.iframeAuto(index);

        parent.$('#citybox a').each(function(){
            var id = $(this).find('[name="classification_ids[]"]').val();
            $('[value="'+id+'"]').attr('checked',true)
        });

        // 全选
        $('[name="checkall"]').on('click', function(){
            var td =$(this).parents('td:first').next('td');
            var checked = $(this).prop('checked');
            if(checked){
                $(td).find('[name="classification_id"]').attr('checked',true)
            }else{
                $(td).find('[name="classification_id"]').attr('checked',false);
            }

            $(td).find('[name="classification_id"]').each(function(){
                var name = $(this).attr('data-name');
                var id = $(this).val();
                parent.$('#city_'+id+'').remove();
                if(checked) {
                    parent.$('#citybox').append('<a href="javascript:;" id="city_' + id + '">' + name + ' <input type="hidden" name="classification_ids[]" value="' + id + '"></a>');
                }
            });

        });

        $('[name="all"]').on('click',function(){
            var checked = $(this).prop('checked');

            if(checked){
                $('[type="checkbox"]').attr('checked',true)
            }else{
                $('[type="checkbox"]').attr('checked',false);
            }

            $('[name="classification_id"]').each(function(){
                var name = $(this).attr('data-name');
                var id = $(this).val();
                parent.$('#city_'+id+'').remove();
                if(checked) {
                    parent.$('#citybox').append('<a href="javascript:;" id="city_' + id + '">' + name + ' <input type="hidden" name="classification_ids[]" value="' + id + '"></a>');
                }
            });

        });

        // 单个选择
        $('[name="classification_id"]').on('click', function(){
            var name = $(this).attr('data-name');
            var id = $(this).val();
            parent.$('#city_'+id+'').remove();
            if($(this).prop('checked')){
                parent.$('#citybox').append('<a href="javascript:;" id="city_'+id+'">'+name+' <input type="hidden" name="classification_ids[]" value="'+id+'"></a>');
            }

        });

    </script>
{/block}

